using System;
using System.Collections.Generic;
using CSI.Directory.Core.Model;
using CSI.Directory.Core.Services;
using log4net;

namespace C3.Directory.Services
{
    public class ManagerService : IManagerService
    {
        public IProfileRepository ProfileRepository { get; set; }
        private static readonly ILog Log = LogManager.GetLogger(typeof(ManagerService));
        public IList<User> GetAllContentManagers()
        {
            return ProfileRepository.GetAllContentManagers();
        }

        public TransactionResult CreateContentManager(User u)
        {
            var t = new TransactionResult() { Successful = false };
            try
            {
                t.ReturnVal = ProfileRepository.CreateContentManager(u);
                if (t.ReturnVal > 0)
                    t.Successful = true;
                return t;


            }
            catch (Exception ex)
            {

                if (ex.InnerException != null) Log.Error(ex.Message + Environment.NewLine + ex.InnerException);
                else Log.Error(ex.Message);
                t.Exception = ex.Message;
                return t;
            }
        }

        public TransactionResult DeleteContentManager(User u)
        {
            var t = new TransactionResult() { Successful = false };
            try
            {
                t.ReturnVal = ProfileRepository.DeleteContentManager(u);
                if (t.ReturnVal > 0)
                    t.Successful = true;
                return t;


            }
            catch (Exception ex)
            {

                if (ex.InnerException != null) Log.Error(ex.Message + Environment.NewLine + ex.InnerException);
                else Log.Error(ex.Message);
                t.Exception = ex.Message;
                return t;
            }
        }

        public TransactionResult RoleContentManager(User u)
        {
            var t = new TransactionResult() { Successful = false };
            try
            {
                t.ReturnVal = ProfileRepository.RoleContentManager(u);
                if (t.ReturnVal > 0)
                    t.Successful = true;
                return t;


            }
            catch (Exception ex)
            {

                if (ex.InnerException != null) Log.Error(ex.Message + Environment.NewLine + ex.InnerException);
                else Log.Error(ex.Message);
                t.Exception = ex.Message;
                return t;
            }
        }

        public void ClearCache()
        {
            throw new NotImplementedException();
        }
    }
}